
package com.ctg.sysmgr.sso.server.data.dao.sys.impl;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.ctg.itrdc.paspsdk.data.dao.impl.BaseDaoImpl;
import com.ctg.sysmgr.sso.server.data.dao.sys.ISystemUserDao;
import com.ctg.sysmgr.sso.server.data.entity.SystemUser;

public class SystemUserDaoImpl extends BaseDaoImpl implements ISystemUserDao{

	private final Logger logger = LoggerFactory.getLogger(this.getClass());
	
	@Override
	public SystemUser getUserByName(String username) {
		try {
			StringBuilder builder = new StringBuilder();
			builder.append("select * from SYSTEM_USER where SYS_USER_CODE = ?");
			List<Object> params = new ArrayList<Object>();
	        params.add(username);
	        
			List<SystemUser> list = this.jdbcFindList(builder.toString(), SystemUser.class, params);
			if(null != list && list.size() > 0 ) {
				logger.info("通过用户名获取用户成功，用户名为 {}，userId为{}。", username, list.get(0).getId());
				return list.get(0);
			} else {
				logger.info("通过用户名获取用户失败，原因是不存在用户名为 {} 的用户。", username);
				return null;
			}
		} catch (Exception e) {
			logger.error("通过用户名获取用户出错，原因是{}。", e.getMessage());
			return null;
		} 
	}

   
}
